package com.handpay.zztong.hp.bean;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.handpay.framework.LuaTableUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import se.krka.kahlua.vm.LuaTable;

public class NoticeInfo implements Parcelable {

    public static final String ID = "_id";
    public static final String USERID = "userId";
    public static final String NOTICEID = "noticeId";
    public static final String TITLE = "title";
    public static final String TIME = "time";
    public static final String TEXT = "text";
    public static final String ISREAD = "isRead";
    public static final String LAST_UPDATETIME = "updateTime";
    public static final String ISDELETE = "isDelete";

    private String id;
    private String userId;// 用户id
    private String noticeId;
    private String title;
    private String time;
    private String text;
    private boolean isRead;
    private boolean isDelete = false;

    public boolean isDelete() {
        return isDelete;
    }

    public void setDelete(boolean isDelete) {
        this.isDelete = isDelete;
    }

    public String getId() {
        return id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getNoticeId() {
        return noticeId;
    }

    public void setNoticeId(String noticeId) {
        this.noticeId = noticeId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public boolean isRead() {
        return isRead;
    }

    public void setRead(boolean isRead) {
        this.isRead = isRead;
    }

    public NoticeInfo(String userId, String noticeId, String title, String time, String text, boolean isRead) {
        super();
        this.userId = userId;
        this.noticeId = noticeId;
        this.title = title;
        this.time = time;
        this.text = text;
        this.isRead = isRead;
    }

    public NoticeInfo(String noticeId, String title, String time, String text, boolean isRead) {
        super();
        this.noticeId = noticeId;
        this.title = title;
        this.time = time;
        this.text = text;
        this.isRead = isRead;
    }

    public NoticeInfo() {
        super();
    }

    public NoticeInfo(String noticeId, String title, String time, String text) {
        super();
        this.noticeId = noticeId;
        this.title = title;
        this.time = time;
        this.text = text;
        this.isRead = false;
    }

    public NoticeInfo(String noticeId, boolean isDelete) {
        super();
        this.noticeId = noticeId;
        this.isDelete = isDelete;
    }

    @Override
    public String toString() {
        return "NoticeInfo [id=" + id + ", userId=" + userId + ", noticeId=" + noticeId + ", title=" + title + ", time=" + time + ", text=" + text + ", isRead=" + isRead + ", isDelete=" + isDelete + "]";
    }

    public static List<NoticeInfo> getNoticeLists(LuaTable luaTable, String items) {
        List<NoticeInfo> infos = new ArrayList<NoticeInfo>();
        if (!TextUtils.isEmpty(items) && TextUtils.isDigitsOnly(items) && Integer.parseInt(items) > 0) {
            LuaTable list = (LuaTable) luaTable.rawget("list");
            if (list != null) {
                Vector<LuaTable> dataList = LuaTableUtil.getArray(list);
                for (LuaTable table : dataList) {
                    NoticeInfo info = new NoticeInfo();
                    String id = (String) table.rawget("noticeId");
                    String title = (String) table.rawget("title");
                    String content = (String) table.rawget("content");
                    String time = (String) table.rawget("time");
                    info.setNoticeId(id);
                    info.setTitle(title);
                    info.setText(content);
                    info.setTime(time);
                    infos.add(info);
                }
            }
        }
        return infos;
    }

//    public static List<NoticeInfo> getNoticeLists(UserNotices bean, String items) {
//        List<NoticeInfo> infos = new ArrayList<NoticeInfo>();
//        if (!TextUtils.isEmpty(items) && TextUtils.isDigitsOnly(items) && Integer.parseInt(items) > 0) {
//            List<UserNotices.NoticeBody> list = bean.getList();
//            if (list != null) {
//                for (UserNotices.NoticeBody table : list) {
//                    NoticeInfo info = new NoticeInfo();
//                    String id = table.getNoticeId();
//                    String title = table.getTitle();
//                    String content = table.getContent();
//                    String time = table.getTime();
//                    info.setNoticeId(id);
//                    info.setTitle(title);
//                    info.setText(content);
//                    info.setTime(time);
//                    infos.add(info);
//                }
//            }
//        }
//        HPLog.d(HPLog.SSX_TAG, infos.toString());
//        return infos;
//    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.userId);
        dest.writeString(this.noticeId);
        dest.writeString(this.title);
        dest.writeString(this.time);
        dest.writeString(this.text);
        dest.writeByte(this.isRead ? (byte) 1 : (byte) 0);
        dest.writeByte(this.isDelete ? (byte) 1 : (byte) 0);
    }

    protected NoticeInfo(Parcel in) {
        this.id = in.readString();
        this.userId = in.readString();
        this.noticeId = in.readString();
        this.title = in.readString();
        this.time = in.readString();
        this.text = in.readString();
        this.isRead = in.readByte() != 0;
        this.isDelete = in.readByte() != 0;
    }

    public static final Parcelable.Creator<NoticeInfo> CREATOR = new Parcelable.Creator<NoticeInfo>() {
        @Override
        public NoticeInfo createFromParcel(Parcel source) {
            return new NoticeInfo(source);
        }

        @Override
        public NoticeInfo[] newArray(int size) {
            return new NoticeInfo[size];
        }
    };
}